<?php 
// +----------------------------------------------------------------------
// | OneKeyAdmin [ Believe that you can do better ]
// +----------------------------------------------------------------------
// | Copyright (c) 2020-2023 http://onekeyadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: MUKE <513038996@qq.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);

namespace app\api\middleware;

use app\api\model\UserToken;
/**
 * 登录检测
 */
class LoginCheck
{
    public function handle($request, \Closure $next)
    {
        $time  = 14*24; // 控制token过期时间(14天)
        $input = input('post.');
        if (! empty($input['token'])) {
            $request->userId = UserToken::where("token", $input['token'])->whereTime("create_time","-$time hours")->value('user_id');
        }
        // 下一步
        return $next($request);
    }
}